package com.niren.deviceservice.config;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.context.scope.refresh.RefreshScopeRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;

/**
 * \* author: wky
 * \* Date: 2024/11/22
 * \* Time: 17:34
 * \* Project: microservice
 * \* Package: com.niren.deviceservice.config
 * \* Version: 1.0.0
 * \* To change this template use File | Settings | File Templates.
 * \* Description:请输入源文件描述
 * \
 */
@Component
@RefreshScope
public class NacosConfig {
    public static NacosConfig instance = null;

    @Value("${useLocalCache}")
    private String useLocalCache;

    @PostConstruct
    private void init() {
        instance = this;
    }

    @EventListener
    public void onRefreshScopeRefreshed(RefreshScopeRefreshedEvent event) {
        // 这里可以添加你的配置变更后的处理逻辑
        System.out.println("配置信息已变更，新的配置值为：" + useLocalCache);
    }

    public String getUseLocalCache() {
        return useLocalCache;
    }
}
